package com.gae.tutorial;

import java.io.IOException;
import javax.servlet.http.*;

import com.gae.tutorial.buisines.SimplePojoManager;
import com.gae.tutorial.pojo.SimplePojo;

@SuppressWarnings("serial")
public class JdoTutorial1Servlet extends HttpServlet {
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
	{
		String action =  req.getParameter("action");
		String text =  req.getParameter("text");
		
		String status = "Nothing happened";
		
		SimplePojoManager spm = new SimplePojoManager(); 
		
		if(action != null){
			if(action.equalsIgnoreCase("put")){
				spm.put(text);
				status = "Ok - Record Addded"; 
			}
			
			if(action.equalsIgnoreCase("get")){ 
				SimplePojo sp = spm.getLast();
				if(sp != null){
					status = sp.getValor();
				} else {
					status = "Not found!";
				}
			}
		}

		try {
			resp.setContentType("text/plain");
			resp.getWriter().write(status);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return;
	}
	
	
	
}
